package com.wjcxf.guonianla.utils;

import android.content.Context;

public class DensityUtils {
    public static int Dp2Px(Context context, float dp) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dp * scale + 0.5f);
    }

    public static int Px2Dp(Context context, float px) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (px / scale + 0.5f);
    }

    public static int getWidthDp(Context context) {
        final int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
        return Px2Dp(context,widthPixels);
    }
    public static int getHeightDp(Context context) {
        final int heightPixels = context.getResources().getDisplayMetrics().heightPixels;
        return Px2Dp(context,heightPixels);
    }
}
